package com.auerdi.ui.fragment.a_home.adapter.delegate;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.auerdi.GlideApp;
import com.auerdi.R;
import com.auerdi.ui.detail.ADProductDetailFragment;
import com.auerdi.ui.fragment.a_home.adapter.items.HomeItemsBean;
import com.example.egghttp.EggLog.L;
import com.example.egghttp.retrofit.beans.goods.Product;
import com.squareup.picasso.Picasso;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

import me.yokeyword.eventbusactivityscope.EventBusActivityScope;

/**
 * Created by zhy on 16/6/22.
 */
public class FisGoodLastList implements ItemViewDelegate<HomeItemsBean> {

    @Override
    public int getItemViewLayoutId() {
        return R.layout.item_home_f_goodlastlist;
    }

    @Override
    public boolean isForViewType(HomeItemsBean item, int position) {

        return item.getRouter().equals(getClass().getSimpleName());
    }

    @Override
    public void convert(ViewHolder holder, HomeItemsBean item, int position) {
        List<Product> banners = (List<Product>) item.getItem();


//        recy_world


        RecyclerView recyLast = holder.getView(R.id.recy_last);

        recyLast.setLayoutManager(new GridLayoutManager(holder.getConvertView().getContext(), 2) {

            @Override
            public boolean canScrollVertically() {
                return false;
            }

        });
        recyLast.setHasFixedSize(true);


        recyLast.setAdapter(new CommonAdapter<Product>(holder.getConvertView().getContext(), R.layout.item_home_last, banners) {
            @Override
            protected void convert(ViewHolder viewHolder, final Product item, int position) {

                ImageView imgView = viewHolder.getView(R.id.img);
                ImageView gPic = viewHolder.getView(R.id.gpic);
                viewHolder.setText(R.id.title, item.getTitle());
                viewHolder.setText(R.id.gname, item.getBnProductGuojiaName());
                viewHolder.setText(R.id.stitle, item.getShareTitle());
                viewHolder.setText(R.id.num, "已团" + item.getPayCount() + "件");


                ImageView tag = viewHolder.getView(R.id.tag);
                viewHolder.setText(R.id.apri, "¥" + item.getSuccessPrice());
                viewHolder.setText(R.id.bpri, "¥" + item.getMarkPrice());


//                Picasso.get().load(item.getLunboImg()).error(R.mipmap.eptb).placeholder(R.mipmap.eptb).resize(750, 352).centerCrop().into(imgView);


                GlideApp.with(viewHolder.getConvertView().getContext())
                        .load(item.getLunboImg())
                        .placeholder(R.mipmap.eptb)
                        .error(R.mipmap.pay_err)
                        .centerCrop()
                        .into(imgView);

                Picasso.get().load(item.getBnProductGuojia()).error(R.mipmap.logo).placeholder(R.mipmap.logo).fit().centerInside().into(gPic);

                viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        EventBusActivityScope.getDefault((Activity) holder.getConvertView().getContext()).post(ADProductDetailFragment.newInstance(item));

                        L.d("hcia", "item:" + item);

                    }
                });


            }
        });


    }
}
